﻿package com.hxh.ocean.controller {
	
	import com.fileitup.fisixengine.core.FisixEngine;
	import com.hxh.ocean.helpers.Helper;
	import com.hxh.ocean.view.SuperObject;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	import org.flintparticles.twoD.renderers.BitmapRenderer;
	
	public class SuperManager extends Sprite {
		
		private var _effectRenderer:BitmapRenderer;
		private var _pause:Boolean;
		protected var _fisixEngine:FisixEngine;
		
		
		// Initialization:
		public function SuperManager() {
			super();
			_effectRenderer = new BitmapRenderer(new Rectangle(0,0,Helper.SCREEN_WIDTH,Helper.SCREEN_HEIGHT));
			_fisixEngine = new FisixEngine();
			addChild(_effectRenderer);
			addEventListener(Event.ENTER_FRAME, startFrame);
		}
		//Initiate the game loop

		public function get Pause():Boolean
		{
			return _pause;
		}

		public function set Pause(v:Boolean):void
		{
			_pause = v;
		}

		public function get EffectRenderer():BitmapRenderer
		{
			return _effectRenderer;
		}

		private function startFrame(evt:Event):void{
			if (!_pause){
				doUpdate();
			}
		}
		/******************* GAME LOOP *********************/

		protected function doUpdate():void{}
		
		/***************************************************/
	
		//Add the game object to the screen
		protected function addChildObject(object:SuperObject):void{
			addChild(object);
			for (var i:uint = 0; i < object.VisualEffects.length; i++){
				_effectRenderer.addEmitter(object.VisualEffects[i]);
			}
		}
	}
	
}